#ifndef DOUBAN_FMRADIO_FMMODULE_P_H
#define DOUBAN_FMRADIO_FMMODULE_P_H

#include "FMModule.h"
#include "ui_RadioFrame.h"
#include <QSystemTrayIcon>
#include <QObject>

class QFrame;
class QNetworkReply;
class QSystemTrayIcon;
class QxtGlobalShortcut;
class QNetworkAccessManager;

namespace Douban
{
	class FMModule;
	class MusicInfo;
	class IPlayerBackend;
	class FMModulePrivate : public QObject
	{
		Q_OBJECT
		const static QString FM_API_URL;

		public:
			FMModulePrivate(FMModule*);
			~FMModulePrivate();

			void setCookie(const QList<QNetworkCookie>&);
			void clearCookie();
			void configChanged();
			bool eventFilter(QObject*, QEvent*);
		private:
			FMModule*			m_pImpl;
			QWidget*			m_fmFrame;
			QFrame*				bgFrame;
			IPlayerBackend*		m_playerBackend;

			bool b_showMusicInfo;
			bool b_useTrayIcon;
			bool b_loggedIn;
			bool b_startNewList;
			bool b_isPlaying;
			bool b_isOpened;
			bool b_trySwitchToPrivate;
			bool b_showBorder;

			bool b_dragStarted;
			QPoint mousePressGPos;
			QPoint relativePos;

			Ui::RadioFrame ui;
			QButtonGroup m_btnGroup;
			FMModule::Channel e_channel;
			FMModule::Channel e_lastChannel;

			QxtGlobalShortcut* m_favSC;
			QxtGlobalShortcut* m_delSC;
			QxtGlobalShortcut* m_dislikeSC;
			QxtGlobalShortcut* m_stopSC;
			QxtGlobalShortcut* m_nextSC;
			QxtGlobalShortcut* m_showSC;
			QSystemTrayIcon* m_trayIcon;
			QMenu* m_trayContextMenu;
			QAction* m_delAct;
			QAction* m_favAct;
			QAction* m_stopAct;
			QAction* m_nextAct;

			DoubanId			i_uid;
			QList<QString>		m_historyIds;
			QList<char>			m_historyTypes;
			QList<MusicInfo*>	m_playList;
			QList<MusicInfo*>	m_recycleList;
			MusicInfo*			m_nowPlaySong;

			QNetworkReply*			m_getCoverReply;
			QNetworkReply*			m_getListReply;
			QNetworkAccessManager*	m_manager;
			QList<QNetworkCookie>	m_cookies;

			void stopFM();
			void startFM();

			void updateUi();
			void showMessage(const QString&);

			void resizePlayList(int length);
			void onSongStatus(char type);
			void reportPlayed();
			void playNext();
			void requireList(char type);

			void clearPlayList();
		private slots:
			void channelBtnClicked(int channel,bool dontGetList = false);
			void togglePlay();
			void volumeChanged(int);
			void favTheSong();
			void unFavTheSong();
			void deleteSong();
			void nextSong();
			void toggleFav();
			void toggleVisible();
			void sysTrayClicked(QSystemTrayIcon::ActivationReason reason);

			void playStart();
			void playError();
			void playComplete();

			void openUrl(const QString&);

			void networkFinished(QNetworkReply*);
			void getPlayListFinished();
			void getCoverFinished();
		friend class FMModule;
	};
}
#endif // FMMODULE_P_H
